package com.lam.monitor.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lam.common.base.controller.BaseController;
import com.lam.common.base.domain.Result;
import com.lam.common.components.dict.annotation.DictAutoTransfer;
import com.lam.common.components.easyexcel.export.DownloadUtil;
import com.lam.framework.annotation.ParamInject;
import com.lam.framework.bean.entity.SysOperLog;
import com.lam.framework.operLog.annotation.Log;
import com.lam.framework.operLog.enums.BusinessType;
import com.lam.system.param.SysOperLogParam;
import com.lam.system.service.SysOperLogService;

/**
 * 操作日志Controller
 * 
 * @author lam
 * @date 2022-07-15
 */
@Log(title = "操作日志")
@ParamInject
@RestController
@RequestMapping("/${adminPath}/monitor/operLog")
public class OperLogController extends BaseController {

    @Autowired
    private SysOperLogService sysOperLogService;

    /**
     * 查询操作日志列表
     */
    @Log(oper="分页查询")
    @DictAutoTransfer
    @PreAuthorize("@ss.hasPm('monitor:operLog:list')")
    @GetMapping("/list")
    public Result list(SysOperLogParam param) {
    
        startPage();
        List<SysOperLog> list = sysOperLogService.selectList(param);
        return Result.ok(getTableData(list));
    }
    
    /**
     * 导出操作日志列表
     */
    @PreAuthorize("@ss.hasPm('monitor:operLog:export')")
    @Log(businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public Result export(SysOperLogParam param) {
    
    	withOrderBy();
        List<SysOperLog> list = sysOperLogService.selectList(param);
        return Result.ok(DownloadUtil.exportExcel("操作日志导出", list, SysOperLog.class));
    }
    
    /**
     * 获取操作日志详细信息
     */
    @DictAutoTransfer
    @Log(oper="根据ID查询")
    @PreAuthorize("@ss.hasPm('monitor:operLog:query')")
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable("id") String id) {
    
        return Result.ok(sysOperLogService.selectById(id));
    }
    
    /**
     * 删除操作日志
     */
    @PreAuthorize("@ss.hasPm('monitor:operLog:remove')")
    @Log(businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public Result remove(@PathVariable String id) {
    
        return toAjax(sysOperLogService.deleteById(id));
    }
    

}
